<?php

	require_once(dirname(__FILE__) . "/../core/safeParam.php");
	
	$cart_order_id = $_GET['oid'];
			
	$cart_object->total();
	$total      = $cart_object->_total;
	$cart_items = $cart_object->getItems();
	
	$bigcart = '
	<div align="center">
		<table width="90%" cellpadding="5" cellspacing="5" id="bigcart">
			<tr>
				<td colspan="2">
					<h1>'. $config['sitename'] .' : Detalles del pedido</h1>
				</td>
			</tr>';
	
	//DESCRIPCION DE PEDIDO
	$bigcart .=	'
	<tr>
		<td colspan="2">
			<table width="100%">
				<tr>
					<td align="center">
						<i>Cantidad</i>
					</td>
					
					<td align="center">
						<i>Producto</i>
					</td>
					
					<td align="center">
						<i>Precio Unitario</i>
					</td>
					
					<td align="center">
						<i>Total</i>
					</td>
				</tr>';
	
	foreach ($cart_items as $cart_item) {
		$item_price 	= $cart_item->price;
  		$item_cantidad = $cart_item->quantity;
  		$subtotal   	= $cart_item->quantity * $item_price;

		$bigcart .="
		<tr>
			<td align='center' style='font-weight:normal;'>
				". $cart_item->quantity ."
			</td>
			
			<td align='center' style='font-weight:normal;'>
				". $cart_item->name ."
			</td>
			
			<td align='center' style='font-weight:normal;'>
				". price_format($cart_item->price) ."
			</td>
			
			<td align='center' style='font-weight:normal;'>
				". price_format($cart_item->price * $cart_item->quantity) ."
			</td>
		</tr>
		";
	}//foreach
	
	$bigcart .='
	</table>
	</td>
	</tr>
	';
			
	$total = $_SESSION['final'];
	
	//COMENTARIOS
	$bigcart .= "
	<tr>
		<td colspan='2' align='left' style='font-weight:normal; font-size:1.2em;'>
			<b><i>". $lang['comments'] .":</i></b> ". $_SESSION['comments'] ."
		</td>
	</tr>";

	//TOTALES
	$bigcart .= "
	<tr>
		<td align=right width='90%'>
			<b><i>". $lang['subtotal'] .":</i></b> 
		</td>
		
		<td align='right' style='font-weight:normal;'>
			". price_format($_SESSION['subtotal']) ."
		</td>
	</tr>";
	
	$bigcart .= "
	<tr>
		<td align='right'>
			<b><i>" . $lang['tax'] . ":</i></b> 
		</td>
		
		<td align='right' style='font-weight:normal;'>
			". price_format($_SESSION['tax']) ."
		</td>
	</tr>";
		
	$bigcart .= "
	<tr>
		<td align='right' style='color:red;'>
			<b><i>". $lang['total'] .":</i></b>
		</td>
		
		<td align='right' style='font-weight:normal;'>
			". price_format($total) ."
		</td>
	</tr>";
	
	$bigcart .= "
	<tr>
		<td align='right'>
			<b><i>Abono :</i></b>
		</td>
		
		<td align='right' style='font-weight:normal;'>
			". price_format($_SESSION['abono']) ."
		</td>
	</tr>";
	
	$bigcart .= "
	<tr>
		<td align='right' style='color:green;'>
			<b><i>Vuelto:</i></b>
		</td>
		
		<td align='right' style='font-weight:normal;'>
			". price_format($_SESSION['abono'] - $total) ."
		</td>
	</tr>";
	
	$bigcart .= '
	</table>
	</div>';
	
	$final_cart = $bigcart;
	
	if ($_GET['f'] == 1) {
  		// payment failed
  		$smarty->assign('f', 1);
	} else {
  		// payment successful
  		if ($_SESSION['location'] != '') {
    		$location_info = locationArray($_SESSION['location']);
    		define('ORDER_EMAIL', $location_info[0]['email']);
  		} else {
    		define('ORDER_EMAIL', ADMIN_EMAIL);
  		}
  		
  		unset($_SESSION['MYFAUCART']);
  		
  		$results      = $database->select("SELECT * FROM order_sum where id = $cart_order_id");
  		$results_user = $database->select("SELECT * FROM users where id = " . $results[0]['uid'] . "");
  		$up['status'] = 0;
  		$update = $database->update_array("order_sum", $up, "id=$cart_order_id");
  		

  		//$message = completeOrder($cart_order_id, $cc_info);

		
		$smarty->assign('cart_order_id', $cart_order_id);
  		$smarty->assign('cart_contents', $final_cart);
  		$smarty->assign('cart', $results[0]);
  		
  		$cart_object->emptyCart();
  		unset($_SESSION['cc']);
  		unset($_SESSION['subtotal']);
  		unset($_SESSION['tax']);
  		unset($_SESSION['sub']);
  		unset($_SESSION['pickup_discount']);
  		unset($_SESSION['cart_order_id']);
  		unset($_SESSION['comments']);
  		unset($_SESSION['location']);
  		unset($_SESSION['final']);
  		unset($_SESSION['delivery']);  		
  		unset($_SESSION['abono']);
  		
  		toSession();
	}
?>
